Subject: The 3d proggy. (4k [ish])
From: Scott Southurst <[email-masked]>
To: LIST AMOS <[email-masked]>
Date: Sun, 3 Oct 1993 16:55:14 +1000 (EST)

Coz people keep asking me for the 3d proggy I previously mentioned I have
decided to send it to the list.  NOTE: It is only a simple routine.  It
rotates the defined object around 2 axis.  The Y-axis (Moveable axis) and
the x axis (fixed).  The program has been written to give people an idea
of how 3d gfx is done and how hidden vertices is done.  When I improve the
rotations etc. I'll notify all.

WANTED:  A "Blank extension" source code.  I have the "remains" of source
codes but they don't seem to work when I remove the code so that they
compile (ie. I remove all the functions etc. so that the file may be used
as a template).  The files then compile but AMOS won't boot (AMOS
Creator v1.34)

NOTE 2: There is a slight error in the definition of the object.  I think
it may be due to the equations I used (Not mine,  I got them from a book).
 I'll have to dig out my equations to see where the error lies.  The
object will still work OK but the direction it may face will not be as
expected.

8<-------------------------cut here----------------------------------------
'                                                             
'                   Maverick 1993.                               
'                                                             
'                     27-9-1993                                 
'
'   NOTE:  The documentation has been provided for those who need to 
'          learn from this program.  One interesting thing which can 
'          be learnt is that comments take time when the program  is 
'          run in the interpreter.  What this means is for the prog- 
'          ram to be viewed at  its best remove the comments  before 
'          running (OR compile it).
'
Set Buffer 20
Degree 
Screen Open 0,320,256,16,0
Flash Off 
Curs Off 
Hide 
Cls 0
Double Buffer 
Autoback 0
'
Close Editor 
Close Workbench 
'
Dim OBJ(200,12),SYN(360),COZ(360)
Global OBJ(),SYN(),COZ(),S
SETUP
PITCH=0
YAW=0
DELTADEG=15
'
'   Main Loop
'
Repeat 
   Add PITCH,DELTADEG*(Jup(1)-Jdown(1)),DELTADEG To 360
   Add YAW,DELTADEG*(Jleft(1)-Jright(1)),DELTADEG To 360
   ROTATE[YAW,PITCH]
   Screen Swap 
   Wait Vbl 
   Cls 0
Until Mouse Key<>0 or Fire(1)
'
'   End of program 
'
Procedure SETUP
'
'    This procedure is used to setup the arrays.  SYN contains the sine
'    values for deg=0 to 360.  COZ is the same for the cosine values.
'    OBJ contains the points for the object:-
'      OBJ(n,1) = x1   OBJ(n,2) = y1   OBJ(n,3) = z1 ... 
'      OBJ(n,9) = z3 
'
   For COUNT=0 To 360
      SYN(COUNT)=10000*Sin(COUNT)
      COZ(COUNT)=10000*Cos(COUNT)
   Next COUNT
   Restore DATER
   Repeat 
      Inc PNTS
      For COUNT=0 To 9
         Read OBJ(PNTS,COUNT)
      Next COUNT
      Read WORD$
   Until WORD$="ENDDATA"
'
'   The following stores the number of faces in the object.
'
   OBJ(0,0)=PNTS
'
'   The following contains the data for all the points in the object.
'   Three points per polygon.  "CONT" is meaningless.  "ENDDATA" marks 
'   the end of the data for the object.
'   The first field in the object is the colour of the polygon.
'   For the hidden face calculations to be consistant the points MUST
'   be defined in an anticlockwise direction when looking at the face
'   "HEAD-ON" (ie. from out of the object in)
'
DATER:
   Data 6,30,15,30,30,15,-30,0,-15,0,"CONT"
   Data 4,-30,15,30,30,15,30,0,-15,0,"CONT"
   Data 6,-30,15,-30,-30,15,30,0,-15,0,"CONT"
   Data 4,30,15,-30,-30,15,-30,0,-15,0,"CONT"
   Data 15,30,15,30,-30,15,-30,30,15,-30,"CONT"
   Data 13,-30,15,-30,30,15,30,-30,15,30,"ENDDATA"
End Proc
Procedure ROTATE[YAW,PITCH]
   '
   '   Put simply this procedure draws the object.
   '
   For COUNT=1 To OBJ(0,0)
      '
      '   First the object is rotated about the Y axis (YAWED).
      '
      X1=((OBJ(COUNT,3)*COZ(YAW))/10000)-((OBJ(COUNT,1)*SYN(YAW))/10000)
      X2=((OBJ(COUNT,6)*COZ(YAW))/10000)-((OBJ(COUNT,4)*SYN(YAW))/10000)
      X3=((OBJ(COUNT,9)*COZ(YAW))/10000)-((OBJ(COUNT,7)*SYN(YAW))/10000)
      Z1=((OBJ(COUNT,3)*SYN(YAW))/10000)+((OBJ(COUNT,1)*COZ(YAW))/10000)
      Z2=((OBJ(COUNT,6)*SYN(YAW))/10000)+((OBJ(COUNT,4)*COZ(YAW))/10000)
      Z3=((OBJ(COUNT,9)*SYN(YAW))/10000)+((OBJ(COUNT,7)*COZ(YAW))/10000)
      '
      '   Next the object is rotated about the X axis (PITCHED). 
      '
      Y1=((OBJ(COUNT,2)*COZ(PITCH))/10000)-((Z1*SYN(PITCH))/10000)
      Y2=((OBJ(COUNT,5)*COZ(PITCH))/10000)-((Z2*SYN(PITCH))/10000)
      Y3=((OBJ(COUNT,8)*COZ(PITCH))/10000)-((Z3*SYN(PITCH))/10000)
      Z1=((OBJ(COUNT,2)*SYN(PITCH))/10000)+((Z1*COZ(PITCH))/10000)
      Z2=((OBJ(COUNT,5)*SYN(PITCH))/10000)+((Z2*COZ(PITCH))/10000)
      Z3=((OBJ(COUNT,8)*SYN(PITCH))/10000)+((Z3*COZ(PITCH))/10000)
      '
      '   The normal vector for the face is calculated.
      '
      A=(Y1*(Z2-Z3))+(Y2*(Z3-Z1))+(Y3*(Z1-Z2))
      B=(X1*(Z3-Z2))+(X2*(Z1-Z3))+(X3*(Z2-Z1))
      C=(X1*(Y2-Y3))+(X2*(Y3-Y1))+(X3*(Y1-Y2))
      Ink OBJ(COUNT,0)
      '
      '   If the face is pointing into the screen then don't draw. 
      '
      If C=>0
         Polygon X1+160,Y1+128 To X2+160,Y2+128 To X3+160,Y3+128
      End If 
   Next COUNT
End Proc
8<-------------------------cut here----------------------------------------